<?php

namespace app\logic;

use GatewayWorker\Lib\Gateway;

class MessageLogic
{


    public static function send($data, $user)
    {
        Gateway::$registerAddress = config('gateway_worker.registerAddress');
        //用户是否在线
        // trace(Gateway::isUidOnline($data['uid']), 'api_error');
        $content = [
            'type' => 'alone',
            'id' => $data['uid'],
            'data' => [
                'uid' => $user['uid'],
                'name' => '',//昵称
                'icon' => '',//头像
                'type' => $data['type'],
                'content' => $data['content'],
                'time' => time()
            ]
        ];
        Gateway::sendToUid($data['uid'], json_encode($content));
    }

    public static function send_group($data, $user)
    {
        $content = [
            'type' => 'group',
            'id' => $data['group_id'],
            'data' => [
                'uid' => $user['uid'],
                'name' => '',//昵称
                'icon' => '',//头像
                'type' => $data['type'],
                'content' => $data['content'],
                'time' => time()
            ]
        ];
        Gateway::$registerAddress = config('gateway_worker.registerAddress');
        Gateway::sendToGroup($data['group_id'], json_encode($content));
    }
}